home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / tool / fapxtool / src / txl / txlrtn.c < prev    next >
C/C++ Source or Header  |  1995-02-11  |  2KB  |  120 lines

  1. /***************
  2. *
  3. * g:\exe\txl\src\txlrtn.c
  4. */
  5. #include "txl.h"
  6.  
  7. void markrtnlist(unsigned int *dlst, unsigned int maxno, FILE *fp)
  8. {
  9.     int i = 0, listno;
  10.  
  11.     while (!feof(fp)) {
  12.         fgets(line1, 80, fp);
  13.         if (sscanf(line1 + 1, "%d", &listno)) {
  14.             while (dlst[i] < listno) {
  15.                 i++;
  16.             }
  17.             if (dlst[i] == listno) {
  18.                 if (*(line1) == '+') {
  19.                     *(line1) = ' ';
  20.                 }
  21.                 else {
  22.                     *(line1) = '+';
  23.                 }
  24.             }
  25.         }
  26.         fputs(line1, fpmes);
  27.     }
  28. }
  29.  
  30. unsigned int readnum(unsigned int base,unsigned int *dlst, char *str)
  31. {
  32.     unsigned int i = base;
  33.     char *tmp = str;
  34.  
  35.     while (strchr(tmp, ',') != NULL) {
  36.         sscanf(tmp, "%d", &(dlst[i]));
  37.         i++;
  38.         i &= 8191;                        /* 念の為ループ    */
  39.         tmp = strchr(tmp, ',') + 1;
  40.     }
  41.     sscanf(tmp, "%d", &(dlst[i]));
  42.     return (i + 1);
  43. }
  44.  
  45. unsigned int readnumfile(unsigned int *dlst, char *fname)
  46. {
  47.     FILE *fp;
  48.     unsigned int i = 0;
  49.  
  50.     if ((fp = fopen(fname, "rt")) == NULL) {
  51.         fprintf(stderr, "TXL:can't open '%s'", fname);
  52.         Exit(1);
  53.     }
  54.     while (!feof(fp)) {
  55.         fgets(line1, 80, fp);
  56.         if (*line1 != '\n') {
  57.             i = readnum(i, dlst, line1);
  58.         }
  59.     }
  60.     fclose(fp);
  61.     return (i);
  62. }
  63.  
  64. int cmprtn(unsigned int *x, unsigned int *y)
  65. {
  66.     return ((int)((long)(*x) - (long)(*y)));
  67. }
  68.  
  69. void rtnmark()
  70. {
  71.     FILE *fp;
  72.     unsigned int *dlst;
  73.     unsigned int maxno;
  74.  
  75.     if ((dlst = calloc(8193, sizeof(unsigned int))) == NULL) {
  76.         errexit("out of memory");
  77.     }
  78.  
  79.     if ((fp = fopen(inputfile, "rt")) == NULL) {
  80.         free(dlst);
  81.         fprintf(stderr, "TXL:can't open '%s'", inputfile);
  82.         Exit(1);
  83.     }
  84.     fgets(line1, 80, fp);
  85.     fputs(line1, fpmes);
  86.     fgets(line1, 80, fp);
  87.     fputs(line1, fpmes);
  88.     fgets(line1, 80, fp);
  89.     fputs(line1, fpmes);
  90.     fgets(line1, 80, fp);
  91.     fputs(line1, fpmes);    /* 空読み */
  92.  
  93.     if (*outputfile == '&') {
  94.         maxno = readnumfile(dlst, outputfile + 1);
  95.     }
  96.     else {
  97.         maxno = readnum(0, dlst, outputfile);
  98.     }
  99.     qsort(dlst, maxno, sizeof(unsigned int), cmprtn);
  100.     dlst[maxno] = 65535;
  101.     markrtnlist(dlst, maxno, fp);
  102.     fclose(fp);
  103.     free(dlst);
  104. }
  105.  
  106. void rtninit()
  107. {
  108.     fprintf(stderr, "TXL: open RTN_ListMarker\n");
  109. }
  110.  
  111. void rtndriver(char *val[])
  112. {
  113.     rtninit();
  114.  
  115.     outputfile = val[0];    /* & or numbers    */
  116.     inputfile = val[1];        /* rtn */
  117.     rtnmark();
  118.     Exit(0);
  119. }
  120.